package com.watson.db.controller;

import com.watson.db.enrity.User;
import com.watson.db.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author watson
 * @Date 2022/7/6 21:01
 * @Description: TODO
 * @Version 1.0
 */
@RestController
public class TestController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/test")
    public void testUser() {
        User user = new User();
        user.setName("test1");

        // add for test
        userMapper.insert(user);

        // select for test
        user = userMapper.selectById(user.getId());

        // delete for test
        userMapper.deleteById(3L);

        // update for test
        User newUser = new User();
        newUser.setId(1L);
        user.setName("mp");
        userMapper.updateById(user);

        // count for test
        System.out.println(userMapper.myCount());

        userMapper.getAddrAndUser(null).forEach(System.out::println);
        userMapper.getAddrAndUser("add").forEach(System.out::println);
        userMapper.getUserAndAddr(null).forEach(System.out::println);
        userMapper.getUserAndAddr("test1").forEach(System.out::println);
    }
}
